import React, { Component } from "react";
import "./index.css";

import Header from "./components/Header";
import Main from "./components/Main";
import Footer from "./components/Footer";

import axios from "axios";

export default class App extends Component {
  state = {
    list: [],
  };

  // 组件初始化后去获取接口任务列表
  async componentDidMount() {
    const res = await axios.get("http://localhost:5000/todos");
    this.setState({ list: res.data });
  }
   addList = async (content)=>{
    const res = await axios.post('http://localhost:5000/todos',{
        name:content,
        done:false
    })
    this.componentDidMount()
    console.log(res);
    this.setState({
      
    })
  }
  render() {
    return (
      <section className="todoapp">
        <Header addList={this.addList}></Header>
        <Main list={this.state.list} />
        <Footer />
      </section>
    );
  }
}
